package com.ting.test.algorithms.strings;

import java.util.HashMap;
import java.util.HashSet;
import java.util.Set;

/**
 * Created by 雷霆 on 2020/4/7.
 * <p>
 * Description：
 */
public class UniqueStr {

    public static boolean isUnique2(String astr) {
        if (null == astr) {
            return true;
        }
        int length = astr.trim().length();
        if (length == 0) {
            return true;
        }
        if (length > 52) {
            return false;
        }
        Set set = new HashSet();

        for (int i = 0; i < length; i++) {
            set.add(astr.charAt(i));
        }
        return set.size() == length;
    }

    public static boolean isUnique(String astr) {
        if (null == astr) {
            return true;
        }
        int length = astr.trim().length();
        if (length == 0) {
            return true;
        }
        if (length > 52) {
            return false;
        }
        String tempstr;
        for (int i = 0; i < length; i++) {
            tempstr = astr.substring(0, i) + astr.substring(i + 1);
            int index = tempstr.indexOf(astr.charAt(i));
            if (index > 0) {
                return false;
            }
        }
        return true;
    }

    public static void main(String[] args) {
     //   String aaa = "aa";
       // isUnique(aaa);
        String path=System.getProperty("sun.boot.class.path");
        System.out.println(path.replaceAll(";",System.lineSeparator()));

        String path1=System.getProperty("sun.boot.class.path");
        System.out.println(path.replaceAll(";",System.lineSeparator()));
    }
}
